home *** CD-ROM | disk | FTP | other *** search
-
- #include "main.h"
-
-
- //Inicializacia
- //----------------------------------------------------------
- void MESSERSCHMITT::Initialize()
- {
-
- //gulky
- //--------------
- Bullet.Initialize();
- Bullet.UnFriendly = true;
-
- //zvuk
- //------------
- if (SoundEnabled3D == 1)
- {
- Sound.InitialiseForWavMidi3D();
- Sound.LoadSound("sounds/messerschmitt.wav");
- }
-
- //reset hodnot
- //------------
- Reset();
- }
-
- //reset hodnot - na konci kazdej hry
- //----------------------------------------------------------
- void MESSERSCHMITT::Reset()
- {
-
- BulletTime = 0.0f;
-
- Mode = 0;
-
- Bullet.Reset();
-
- Active = false;
- ActiveTime = 0.0f;
- Life = 1;
-
- SoundPlay = false;
- Sound.Stop();
-
- NormalMode = true;
- CrazyMode = false;
- DestroyedMode = false;
-
- Sledovanie = true;
- Vyhybanie = false;
- Uhybanie = false;
- AITime = 0.0f;
-
- Pos = Get3D(0.0f,0.0f,0.0f);
- Rot = Get3D(0.0f,0.0f,0.0f);
- Matrix = GetMatrix(Pos,Rot,F_Scale);
-
- VrtulaRotation = 0.0f;
-
- }
-
- //zastavi zvuk
- //-------------------------------------------------------------
- void MESSERSCHMITT::StopSound()
- {
- SoundPlay = false;
- Sound.Stop();
- }
-
- //Refresh
- //--------------------------------------------------------------
- void MESSERSCHMITT::Refresh()
- {
-
- //ak nieje aktivny tak vyskoc
- if (Active == false)
- return;
-
- //---------------------------------------
- //vyberie parametre podla modu AI
- //---------------------------------------
- if (Mode == 0)
- {
- SteerZ1 = MesserSchmitt_BeSteerZ1 ;
- SteerZ2 = MesserSchmitt_BeSteerZ2 ;
- SteerZ3 = MesserSchmitt_BeSteerZ3 ;
- SteerX1 = MesserSchmitt_BeSteerX1 ;
- SteerX2 = MesserSchmitt_BeSteerX2 ;
- SteerX3 = MesserSchmitt_BeSteerX3 ;
- MaxSteerZ = MesserSchmitt_BeMaxSteerZ;
- MaxSteerX = MesserSchmitt_BeMaxSteerX ;
- }
- if (Mode == 1)
- {
- SteerZ1 = MesserSchmitt_AdSteerZ1;
- SteerZ2 = MesserSchmitt_AdSteerZ2;
- SteerZ3 = MesserSchmitt_AdSteerZ3;
- SteerX1 = MesserSchmitt_AdSteerX1;
- SteerX2 = MesserSchmitt_AdSteerX2;
- SteerX3 = MesserSchmitt_AdSteerX3 ;
- MaxSteerZ = MesserSchmitt_AdMaxSteerZ ;
- MaxSteerX = MesserSchmitt_AdMaxSteerX ;
- }
-
- //-------------------------------------
- //vypocitanie matice podla ktorej sa posunie
- //------------------------------------
- Matrix = GetMatrix(Pos,Rot,F_Scale);
-
- //------------------
- //umela inteligencia
- //------------------
- if (NormalMode)
- {
-
- if (Sledovanie)
- ProcessSledovanie();
- else if(Vyhybanie)
- ProcessVyhybanie();
- else if(Uhybanie)
- ProcessUhybanie();
-
- }
-
- //---------
- //posunutie
- //---------
- if (NormalMode || CrazyMode)
- {
-
- Pos = TransformPoint(Get3D(0.0f,0.0f,Power(MesserSchmitt_Speed)),
- Matrix);
-
- //ak vysiel pri pade mimo - otoc
- if (CrazyMode = true)
- {
- if ((Pos.X < -F_MapSize || Pos.X > F_MapSize) ||
- (Pos.Y < -F_MapSize || Pos.Y > F_MapSize) ||
- (Pos.Z < -F_MapSize || Pos.Z > F_MapSize))
- {
- Rot.Y = Rot.Y - 3.14f;
- }
- }
-
- }
-
- //-------------------------------------
- //vypocitanie matice a koliznych bodov
- //------------------------------------
- Matrix = GetMatrix(Pos,Rot,F_Scale);
-
- //kolizne body
- PL = MesserSchmitt_Left;
- PR = MesserSchmitt_Right;
- PU = MesserSchmitt_Up;
- PD = MesserSchmitt_Down;
- PF = MesserSchmitt_Front;
- PB = MesserSchmitt_Back;
-
- PL = TransformPoint(PL,Matrix);
- PR = TransformPoint(PR,Matrix);
- PB = TransformPoint(PB,Matrix);
- PF = TransformPoint(PF,Matrix);
- PU = TransformPoint(PU,Matrix);
- PD = TransformPoint(PD,Matrix);
-
- //gulomety
- BL = TransformPoint(MesserSchmitt_BulletLeft,Matrix);
- BR = TransformPoint(MesserSchmitt_BulletRight,Matrix);
-
- //vrtula
- PV = TransformPoint(MesserSchmitt_VrtulaPoint,Matrix);
-
- //----------------
- //kolizia so zemov
- //----------------
- bool GroundCollision = GetGroundCollision();
-
- //-------------
- //Zvuk motora
- //-------------
- if (NormalMode || CrazyMode)
- {
- if (SoundPlay == false && Menu.EnabledBriefring == false)
- {
- SoundPlay = true;
- Sound.Play(true);
- }
-
- Sound.SetPosition(Pos,MesserSchmitt_SoundScale);
- }
-
- //-------------
- //process
- //-------------
- if (NormalMode)
- {
-
- //kolizia zo zemov
- if (GroundCollision == true)
- {
- //particle
- Explo.SpawnExplosion(Pos);
- Explo.SpawnParticle(Pos);
- Explo.F_Plane.Spawn(Pos);
- Explo.F_Ball.Spawn(Pos);
-
- DestroyedMode = true;
- NormalMode = false;
- Life = -1;
-
- //zvuk
- SoundLib.ExplodeLarge.SetPosition(Pos,ExplodeLarge_Scale);
- SoundLib.ExplodeLarge.Play();
-
- //zastav zvuk motora
- Sound.Stop();
- }
-
- //zivoty
- if (Life <= 0)
- {
- //particle
- Explo.SpawnExplosion(Pos);
- Explo.SpawnParticle(Pos);
- Explo.F_Plane.Spawn(Pos);
- Explo.F_Ball.Spawn(Pos);
-
- CrazyMode = true;
- NormalMode = false;
-
- //zvuk
- SoundLib.ExplodeSmall.SetPosition(Pos,ExplodeSmall_Scale);
- SoundLib.ExplodeSmall.Play();
-
- //vypusti score particle
- if (SpitFire.Life > 0)
- Score.DrawScore(Score_MesserSchmitt,Pos);
-
- //pripocita score
- if (SpitFire.Life > 0)
- SpitFire.Score += Score_MesserSchmitt;
- }
-
- }
- else if(CrazyMode)
- {
-
- //kolizia zo zemov
- if (GroundCollision == true)
- {
-
- //particle
- Explo.SpawnExplosion(Pos);
- Explo.SpawnParticle(Pos);
- Explo.F_Plane.Spawn(Pos);
- Explo.F_Ball.Spawn(Pos);
-
- DestroyedMode = true;
- CrazyMode = false;
-
- //zvuk
- SoundLib.ExplodeLarge.SetPosition(Pos,ExplodeLarge_Scale);
- SoundLib.ExplodeLarge.Play();
-
- //zastav zvuk motora
- Sound.Stop();
- }
-
- //crazy
- Rot.Z += Power(0.1f);
- Rot.X += Power(0.005f);
- Pos.Y -= Power(2.0f);
-
- //particle
- Explo.SpawnSmokePlane(Pos);
- Explo.SpawnSmokeHit(Pos);
-
- }
- else if(DestroyedMode)
- {
- Explo.SpawnSmokeGround(Pos);
-
- ActiveTime += PowerTime(1.0f);
- if (ActiveTime > MesserSchmitt_DestroyTime)
- Active = false;
- }
-
- //----------
- //Render
- //-----------
-
- //Naboje
- Bullet.Refresh();
-
- //Normal
- if ((NormalMode)||(CrazyMode))
- {
- //model
- ModelLib.MesserSchmitt_ModelNormal.Pos = Pos;
- ModelLib.MesserSchmitt_ModelNormal.Rot = Rot;
- ModelLib.MesserSchmitt_ModelNormal.Render();
-
- //vrtula
- VrtulaRotation += Power(MesserSchmitt_Speed/20.0f);
-
- ModelLib.Vrtula.Pos = PV;
- ModelLib.Vrtula.Rot = Rot;
- ModelLib.Vrtula.Rot.Z = VrtulaRotation;
- ModelLib.Vrtula.Color.A = 0.6f;
-
- Engine.SetAlphaTest(true);
- Engine.SetBlendTrans();
- ModelLib.Vrtula.Render();
- Engine.SetBlendNone();
-
-
- }
-
- //destroyed
- else if(DestroyedMode)
- {
- ModelLib.MesserSchmitt_ModelDestroyed.Pos = Pos;
- ModelLib.MesserSchmitt_ModelDestroyed.Rot = Rot;
- ModelLib.MesserSchmitt_ModelDestroyed.Render();
- }
-
-
- }
-
- //umela inteligencia prechadzanie
- //--------------------------------------------------------
- void MESSERSCHMITT::ProcessSledovanie()
- {
-
- //cas
- //-------
- AITime += PowerTime(1.0f);
-
-
- //urci bod ktory ma sledova¥
- //----------------------------
- SpitFirePoint = UnTransformPoint(SpitFire.SlPoint, Matrix);
- Distance = CalcDistance(Get3D(0.0f,0.0f,0.0f),SpitFirePoint);
-
- //strelba
- //----------
- BulletTime += PowerTime(1.0f);
- if (SpitFirePoint.X > -50.0f && SpitFirePoint.X < 50.0f &&
- SpitFirePoint.Y > -50.0f && SpitFirePoint.Y < 50.0f &&
- SpitFirePoint.Z > 0.0f && SpitFirePoint.Z < 2500.0f && BulletTime > MesserSchmitt_BulletFreq)
- {
- //vypusti bullet
- Bullet.SpawnBullet(BL,Rot);
- Bullet.SpawnBullet(BR,Rot);
- BulletTime = 0.0f;
-
- //zvuk
- SoundLib.FireUnFriendly.SetPosition(Pos,FireUnFriendly_Scale);
- SoundLib.FireUnFriendly.Play();
- }
-
- //vodorovne
- //---------
- if (SpitFirePoint.Z > 0.0f)
- {
- if (SpitFirePoint.X > 0.0f)
- {
- if ((Rot.Z-Power(SteerZ2)) > -MaxSteerZ )
- {
- if (Rot.Z <= 0.0f)
- Rot.Z -= Power(SteerZ1)*(SpitFirePoint.X/Distance);
- if (Rot.Z > 0.0f)
- Rot.Z -= Power(SteerZ2);
- }
- }
- if (SpitFirePoint.X < 0.0f)
- {
- if ((Rot.Z+Power(SteerZ2)) < MaxSteerZ )
- {
- if (Rot.Z >= 0.0f)
- Rot.Z -= Power(SteerZ1)*(SpitFirePoint.X/Distance);
- if (Rot.Z < 0.0f)
- Rot.Z += Power(SteerZ2);
- }
- }
-
- }
- //-----
- if (SpitFirePoint.Z < 0.0f)
- {
- if (SpitFirePoint.X > 0.0f)
- {
- if ((Rot.Z-Power(SteerZ2)) > -MaxSteerZ)
- {
- if (Rot.Z >= 0.0f)
- Rot.Z -= Power(SteerZ2);
- if (Rot.Z < 0.0f)
- Rot.Z -= Power(SteerZ1);
- }
- }
- if (SpitFirePoint.X < 0.0f)
- {
- if ((Rot.Z+Power(SteerZ2)) < MaxSteerZ)
- {
- if (Rot.Z >= 0.0f)
- Rot.Z += Power(SteerZ1);
- if (Rot.Z < 0.0f)
- Rot.Z += Power(SteerZ2);
- }
- }
- }
-
- //RotaciaY
- Rot.Y -= Power(sinf(Rot.Z)*0.04f);
-
- //horizontalne
- //------------
- SpitFirePoint.Y = SpitFire.SlPoint.Y - Pos.Y;
-
- if (SpitFirePoint.Y > 0.0f)
- {
- if ((Rot.X-Power(SteerX2)) > -MaxSteerX )
- {
- if (Rot.X <= 0.0f)
- Rot.X -= Power(SteerX1)*(SpitFirePoint.Y/Distance);
- if (Rot.X > 0.0f)
- Rot.X -= Power(SteerX2);
- }
- }
- if (SpitFirePoint.Y < 0.0f)
- {
- if ((Rot.X+Power(SteerX2)) < MaxSteerX )
- {
- if (Rot.X >= 0.0f)
- Rot.X -= Power(SteerX1)*(SpitFirePoint.Y/Distance);
- if (Rot.X < 0.0f)
- Rot.X += Power(SteerX2);
- }
- }
-
- VECTOR3D P;
- int i;
-
- //kolizia s messerschmittom
- //------------------------------
- P = TransformPoint(Get3D(0.0f,0.0f,40.0f),Matrix);
- for (i=0;i<Max_MesserSchmitt;i++)
- {
- if (Level.MesserSchmitt[i].Pos.X == Pos.X &&
- Level.MesserSchmitt[i].Pos.Y == Pos.Y &&
- Level.MesserSchmitt[i].Pos.Z == Pos.Z)
- continue;
-
- if (Level.MesserSchmitt[i].Active &&
- Level.MesserSchmitt[i].Life > 0)
- {
- if (Level.MesserSchmitt[i].CollisionBox(Pos,P) == true)
- {
- Uhybanie = true;
- Sledovanie = false;
- AITime = 0.0f;
- }
- }
- }
-
- //kolizia so zemou - vyhnutie sa
- //------------------------------
- P = TransformPoint(Get3D(0.0f,0.0f,400.0f),Matrix);
-
- if (Level.Krajina.Collise(Pos,P) == true)
- {
- Vyhybanie = true;
- Sledovanie = false;
- AITime = 0.0f;
- }
-
- }
-
- //ai vyhybanie
- //--------------------------------------------------------
- void MESSERSCHMITT::ProcessVyhybanie()
- {
-
- //cas
- //-------
- AITime += PowerTime(1.0f);
-
- if (AITime > MesserSchmitt_VyhybanieMaxTime)
- {
- AITime = 0.0f;
- Sledovanie = true;
- Vyhybanie = false;
- }
-
- //uhnutie sa
- //-------------
- if (Rot.X - Power(SteerX3) > -MaxSteerX)
- Rot.X -= Power(SteerX3);
-
- }
-
- //ai uhybanie
- //--------------------------------------------------------
- void MESSERSCHMITT::ProcessUhybanie()
- {
-
- //cas
- //-------
- AITime += PowerTime(1.0f);
-
- if (AITime > MesserSchmitt_UhybanieMaxTime)
- {
- AITime = 0.0f;
- Sledovanie = true;
- Uhybanie = false;
- }
-
- //uhnutie sa
- //-------------
- if ((Rot.Z + Power(SteerZ3)) < MaxSteerZ )
- Rot.Z += Power(SteerZ3);
- if ((Rot.X - Power(SteerX1)) > -MaxSteerX )
- Rot.X -= Power(SteerX1);
-
- //rotacia Y
- Rot.Y -= Power(sinf(Rot.Z)*0.04f);
-
- }
-
-
- //kolizia lietadla zo zemov a objektami
- //--------------------------------------------------------
- bool MESSERSCHMITT::GetGroundCollision()
- {
-
- //Zem
- //-------------
- if (Level.Krajina.Collise(PR,PL) == true)
- {
- return true;
- }
- if (Level.Krajina.Collise(PD,PU) == true)
- {
- return true;
- }
- if (Level.Krajina.Collise(PB,PF) == true)
- {
- return true;
- }
-
- return false;
-
- }
-
- //kolizia
- //-------------------------------------------------------------
- bool MESSERSCHMITT::CollisionDetail(VECTOR3D P1, VECTOR3D P2)
- {
- //ak nieje aktivny tak vrat false
- if (Active == false)
- return false;
-
- //ak je zostreleny vrat false
- if (DestroyedMode == true)
- return false;
-
- return ModelLib.MesserSchmitt_ModelNormal.CollisionDetail(P1,P2,Matrix);
- }
-
- //kolizia
- //-------------------------------------------------------------
- bool MESSERSCHMITT::CollisionBox(VECTOR3D P1, VECTOR3D P2)
- {
- //ak nieje aktivny tak vrat false
- if (Active == false)
- return false;
-
- //ak je zostreleny vrat false
- if (DestroyedMode == true)
- return false;
-
- return ModelLib.MesserSchmitt_ModelNormal.CollisionBox(P1,P2,Matrix);
- }
-
-